package com.makeunion.gdlbsdemo.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;

import com.amap.api.maps.AMap;
import com.amap.api.maps.CameraUpdateFactory;
import com.amap.api.maps.MapView;
import com.amap.api.maps.model.CameraPosition;
import com.amap.api.maps.model.LatLng;
import com.makeunion.gdlbsdemo.R;

/**
 * <p>write the description
 *
 * @author renjialiang
 * @version [版本号]
 * @see [相关类/方法]
 * @since [产品/模块版本]
 */
public class NormalMapActivity extends AppCompatActivity implements AMap.OnMapClickListener {

    private MapView mapView;

    private AMap aMap;

    private Boolean firstTouch = true;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_normal_map);

        mapView = (MapView) findViewById(R.id.map_view);
        mapView.onCreate(savedInstanceState); //此方法必须重写
        init();
    }

    private void init() {
        if (aMap == null) {
            aMap = mapView.getMap();
        }
        aMap.showIndoorMap(true);
        aMap.setOnMapClickListener(this);
    }

    @Override
    protected void onResume() {
        super.onResume();
        mapView.onResume();
    }

    /**
     * 方法必须重写
     */
    @Override
    protected void onPause() {
        super.onPause();
        mapView.onPause();
    }

    /**
     * 方法必须重写
     */
    @Override
    protected void onDestroy() {
        super.onDestroy();
        mapView.onDestroy();
    }

    /**
     * 方法必须重写
     */
    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        mapView.onSaveInstanceState(outState);
    }

    @Override
    public void onMapClick(LatLng latLng) {
        if (firstTouch) {
            aMap.animateCamera(
                    CameraUpdateFactory.newCameraPosition(new CameraPosition(
                            new LatLng(39.92463, 116.389139), //经纬度
                            16, //缩放级别 3 -19 3：最大视角，看到全中国，19：最小级别，看到细节
                            60, //视角从垂直于地面，向下倾斜60度，此时与地面夹角是30度
                            90) //地图顺时针旋转90度
                    ),
                    1500,
                    new AMap.CancelableCallback() {
                        @Override
                        public void onFinish() {}

                        @Override
                        public void onCancel() {}
                    }
            );
        } else {
            aMap.animateCamera(
                    CameraUpdateFactory.newCameraPosition(new CameraPosition(
                            new LatLng(39.92463, 116.389139), //经纬度
                            10, //缩放级别 3 -19 3：最大视角，看到全中国，19：最小级别，看到细节
                            0, //视角从垂直于地面，向下倾斜60度，此时与地面夹角是30度
                            -90) //地图顺时针旋转90度
                    ),
                    1500,
                    new AMap.CancelableCallback() {
                        @Override
                        public void onFinish() {}

                        @Override
                        public void onCancel() {}
                    }
            );
        }
        firstTouch = !firstTouch;
    }
}
